﻿package mortal.game.view.copy.worldBoss.worldBossEnter
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.primitives.object2d.*;
    import frEngine.render.layer.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.tileList.*;
    import mortal.game.view.mail.view.*;
    import mortal.mvc.core.*;

    public class WorldSmallBossPanel extends WorldBossBasePanel
    {
        private var _bgBitmapData:BitmapData;
        private var _rect3d:Rect3DObject;
        private var _img2D:Img2D;
        private var _list:G3DTileList;
        private var _rewards:Vector.<MailAttachItem>;

        public function WorldSmallBossPanel(param1:BaseWindow, param2:int)
        {
            this._rewards = new Vector.<MailAttachItem>;
            super(param1, param2);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.intBgBitmapData();
            this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(12, 64, 886, 475), _window);
            Rect3DManager.instance.windowShowHander(null, _window);
            this._img2D = new Img2D(null, this._bgBitmapData, new Rectangle(0, 0, 886, 475), false);
            this._rect3d.addImg(this._img2D, Layer3DManager.backGroudMaskLayer);
            this._list = UIFactory.g3dTileList(19, 68, 900, 475, this._rect3d, _window.contentTopOf3DSprite);
            this._list.setStyle("cellRenderer", this.getCellRenderClass());
            this._list.offsetX = 7;
            this._list.offsetY = 5;
            this._list.columnWidth = 220;
            this._list.rowHeight = 232;
            this._list.verticalGap = 2;
            this._list.configEventListener(Event.CHANGE, this.onListSelectChange);
            GameProxy.player.getHoleBossStat();
            NetDispatcher.addCmdListener(ServerCommand.WorldBossStatChange, this.updateBossList);
            pushUIToDisposeVec(UIFactory.gImageBitmap("smallBossRewardBg.png", 19, 541, _window.contentTopOf3DSprite));
            return;
        }// end function

        protected function getCellRenderClass() : Class
        {
            return WorldSmallBossCellRenderer;
        }// end function

        protected function intBgBitmapData() : void
        {
            if (!this._bgBitmapData)
            {
                this._bgBitmapData = new BitmapData(886, 475, true, 4279244575);
            }
            return;
        }// end function

        protected function updateBossList(param1 = null) : void
        {
            var _loc_2:* = WorldBossConfig.instance.getWorldBossShow(Cache.instance.copy.worldBoss.maxLevel, typeId);
            this._list.dataProvider = new DataProvider(_loc_2);
            if (_loc_2.length)
            {
                this._list.selectedIndex = 0;
                this.onListSelectChange();
            }
            return;
        }// end function

        protected function onListSelectChange(event:Event = null) : void
        {
            var _loc_2:* = this._list.selectedIndex;
            if (_loc_2 >= 0)
            {
                this.updateReward(this._list.dataProvider.getItemAt(_loc_2) as TWorldBoss);
            }
            return;
        }// end function

        protected function updateReward(param1:TWorldBoss) : void
        {
            var _loc_5:MailAttachItem = null;
            var _loc_2:* = new Array();
            if (param1.bossDrop)
            {
                _loc_2 = param1.bossDrop.split("#");
            }
            var _loc_3:* = Math.min(6, _loc_2.length);
            var _loc_4:* = Math.min(this._rewards.length, _loc_2.length);
            var _loc_6:int = 0;
            _loc_6 = 0;
            while (_loc_6 < _loc_4)
            {
                
                _loc_5 = this._rewards[_loc_6];
                _loc_5.itemCode = int(_loc_2[_loc_6]);
                _loc_6++;
            }
            _loc_6 = this._rewards.length - 1;
            while (_loc_6 >= _loc_4)
            {
                
                _loc_5 = this._rewards[_loc_6];
                _loc_5.dispose();
                this._rewards.pop();
                _loc_6 = _loc_6 - 1;
            }
            _loc_6 = _loc_4;
            while (_loc_6 < _loc_3)
            {
                
                _loc_5 = UIFactory.getUICompoment(MailAttachItem, 114 + 47 * _loc_6, 556, _window.contentTopOf3DSprite);
                _loc_5.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                _loc_5.isShowLock = true;
                _loc_5.itemCode = int(_loc_2[_loc_6]);
                this._rewards.push(_loc_5);
                _loc_6++;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._bgBitmapData)
            {
                this._bgBitmapData.dispose();
                this._bgBitmapData = null;
            }
            this._list.dispose(param1);
            this._list = null;
            if (this._rect3d)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
                this._img2D = null;
            }
            var _loc_2:int = 0;
            while (_loc_2 < this._rewards.length)
            {
                
                this._rewards[_loc_2].dispose();
                _loc_2++;
            }
            this._rewards.length = 0;
            NetDispatcher.removeCmdListener(ServerCommand.WorldBossStatChange, this.updateBossList);
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
